//
//  LGMedicineHistogramView.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/3/7.
//

#import "LGMedicineHistogramLayer.h"

@interface LGMedicineHistogramLayer()
/**   */
@property (nonatomic , strong)CAShapeLayer *shapeLayer;
/**  漏服 */
@property (nonatomic , strong)CALayer *leaveLayer;
/**  遮罩层 */
@property (nonatomic , strong)CALayer *maskLayer;

@end

@implementation LGMedicineHistogramLayer

- (instancetype)init{
    self = [super init];
    if(self){
        self.backgroundColor = [UIColor colorWithString:@"#5E8EF5"].CGColor;
        [self addSublayer:self.leaveLayer];
        [self addSublayer:self.maskLayer];
    }
    return self;
}

-(void)setPercent:(CGFloat)percent{
    _percent = percent;
    self.leaveLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height*percent);
    [self layoutSublayers];
}

-(void)setSelecte:(BOOL)selecte{
    _selecte = selecte;
    self.maskLayer.hidden = selecte;
}

-(void)setBackColor:(NSString *)backColor{
    _backColor = backColor;
    self.backgroundColor = [UIColor colorWithString:backColor].CGColor;
}

-(void)setLeaveColor:(NSString *)leaveColor{
    _leaveColor = leaveColor;
    self.leaveLayer.backgroundColor = [UIColor colorWithString:leaveColor].CGColor;
}

-(void)layoutSublayers{
    [super layoutSublayers];
    self.shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(viewPix(6), viewPix(6))].CGPath;
    self.mask = self.shapeLayer;
    self.maskLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height+viewPix(20));
}

-(CAShapeLayer *)shapeLayer{
    if(!_shapeLayer){
        _shapeLayer = [CAShapeLayer layer];
    }
    return _shapeLayer;
}

-(CALayer *)leaveLayer{
    if(!_leaveLayer){
        _leaveLayer = [[CALayer alloc] init];
        _leaveLayer.backgroundColor = [UIColor colorWithString:@"#FB670D"].CGColor;
    }
    return _leaveLayer;
}

-(CALayer *)maskLayer{
    if(!_maskLayer){
        _maskLayer = [[CALayer alloc] init];
        _maskLayer.backgroundColor = [UIColor colorWithString:@"#FFFFFF" alpha:0.3].CGColor;
        _maskLayer.cornerRadius = viewPix(6);
    }
    return _maskLayer;
}



@end
